package com.gw.quotes.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gw.quotes.R;
import com.gw.quotes.entity.business.SearchEstimateEntity.Ordersrecord;
import com.gw.quotes.util.DateUtil;

public class EvaluationAdapter extends BaseAdapter {

	private Context context;
	private int resource;
	private List<Ordersrecord> list;

	public EvaluationAdapter(Context context, int layoutId,
			List<Ordersrecord> list) {
		this.context = context;
		this.resource = layoutId;
		this.list = list;
	}

	@Override
	public int getCount() {
		return list == null ? 0 : list.size();
	}

	@Override
	public Object getItem(int position) {
		return list == null ? null : list.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = (LinearLayout) LayoutInflater.from(this.context)
					.inflate(resource, null);
		}
		if (list == null) {
			return convertView;
		}
		Ordersrecord eva = list.get(position);

		ImageView eva_img = (ImageView) convertView.findViewById(R.id.eva_img);
		TextView order_no = (TextView) convertView.findViewById(R.id.order_no);
		TextView eva_time = (TextView) convertView.findViewById(R.id.eva_time);
		TextView order_company = (TextView) convertView
				.findViewById(R.id.order_company);
		TextView order_total = (TextView) convertView
				.findViewById(R.id.order_total);
		TextView order_qty = (TextView) convertView
				.findViewById(R.id.order_qty);
		TextView text_is_eva = (TextView) convertView
				.findViewById(R.id.text_is_eva);
		order_qty.setText(eva.getQty() + "");
		order_total.setText(eva.getTotal() + "元");
		order_no.setText(eva.getOrdercode());
		eva_time.setText(DateUtil.formatDate("yyyy-MM-dd HH:mm:ss",
				eva.getCreatetime()));
		order_company.setText(eva.getBuyerorgname());

		if (eva.getEstimatestate() == 1) {
			eva_img.setImageResource(R.drawable.flower_1);
			text_is_eva.setText("已评价");
		} else {
			eva_img.setImageResource(R.drawable.flower_3);
			text_is_eva.setText("未评价");
		}

		return convertView;
	}
}
